import _http from '@/_http'
import { Toast } from 'antd-mobile'
import React, { useCallback, useRef } from 'react'
import { withRouter } from 'react-router'

const Index = ({history}) => {
  const account = useRef(null)
  const password = useRef(null)

  const loginit = useCallback(async () => {
    const res = await _http('/user/crmLogin', {
      account: account.current.value,
      password: password.current.value,
    }, 'POST')
    console.log(res, 'res');
    if (res.data.code === 1) {
      Toast.success(res.data.msg)
      localStorage.setItem('isLogin', true)
      history.push('/')
    }else{
      Toast.fail(res.data.msg)
    }
  }, [])
  
  return (
    <div>
      <input type="text" placeholder="账号" ref={account}/>
      <input type="password" placeholder="密码" ref={password}/>
      <button onClick={loginit}>登录</button>
      <style>{`
      input{
        width: 100%;
        height: 80px;
      }
      `}</style>
    </div>
  )
}

export default withRouter(Index)